﻿cmake_minimum_required(VERSION 3.14)

project(gRPCController LANGUAGES CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include($ENV{gRPC_DIR}/gRPCcommon.cmake)

######自动编译.proto######
# Proto file
get_filename_component(hw_proto "*.proto" ABSOLUTE)
get_filename_component(hw_proto_path "${hw_proto}" PATH)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/protocCompiledFiles)
execute_process(COMMAND cmd /c
        protoc
        --grpc_out=${CMAKE_BINARY_DIR}/protocCompiledFiles
        --cpp_out=${CMAKE_BINARY_DIR}/protocCompiledFiles
        -I ${hw_proto_path}
        --plugin=protoc-gen-grpc=${gRPCDIR}/grpc_cpp_plugin.exe
        ${hw_proto}
)
# Include generated *.pb.h files
include_directories(${CMAKE_BINARY_DIR}/protocCompiledFiles)
file(GLOB protocCompiledFiles ${CMAKE_BINARY_DIR}/protocCompiledFiles/*.h ${CMAKE_BINARY_DIR}/protocCompiledFiles/*.cc)


file(GLOB SourceFiles ${SourceFiles} *.proto)
add_library(${PROJECT_NAME}
        ${SourceFiles}
        ${protocCompiledFiles}
)

target_link_libraries(${PROJECT_NAME} PRIVATE ${gRPCAllLibs})